import { Callout } from "nextra/components";
import VideoEmbed from "../../components/video-embed";

# Building Footprint Segmentation

> Extract buildings from satellite imagery

<VideoEmbed
  src="https://geobase-docs.s3.amazonaws.com/geobase-ai-assets/building-footprint-segmentation.mp4"
  title="Building Footprint Segmentation Demo"
/>

<div style={{ textAlign: 'center', marginTop: '1rem' }}>
  <a 
    href="https://docs.geobase.app/geoai-live/tasks/building-footprint-segmentation" 
    target="_blank" 
    rel="noopener noreferrer"
    style={{ 
      display: 'inline-flex', 
      alignItems: 'center', 
      gap: '0.5rem',
      padding: '0.5rem 1rem',
      backgroundColor: '#3b82f6',
      color: 'white',
      textDecoration: 'none',
      borderRadius: '0.375rem',
      fontWeight: '500',
      transition: 'background-color 0.2s'
    }}
    className="live-demo-button"
  >
    🚀 Try Live Demo
  </a>
</div>

<style jsx>{`
  .live-demo-button:hover {
    background-color: #2563eb !important;
  }
`}</style>

<div style={{ textAlign: 'center', marginTop: '0.5rem' }}>
  <a 
    href="https://huggingface.co/geobase/building-footprint-segmentation" 
    target="_blank" 
    rel="noopener noreferrer"
    style={{ 
      fontSize: '0.875rem',
      color: '#6b7280',
      textDecoration: 'none'
    }}
  >
    🤗 View Model on Hugging Face
  </a>
</div>

## Quick Start

```typescript
import { geoai } from "geoai";

// Initialize pipeline
const pipeline = await geoai.pipeline(
  [{ task: "building-footprint-segmentation" }],
  providerParams
);

// Run segmentation
const result = await pipeline.inference({
  inputs: { polygon: myPolygon },
  postProcessingParams: {
    confidenceThreshold: 0.5,
    minArea: 20, // Minimum number of pixels, the unit of area depends on the zoom level.
  },
});

console.log(
  `Extracted ${result.detections.features.length} building footprints`
);
```

## Parameters

### Post-Processing

```typescript
postProcessingParams: {
  confidenceThreshold: 0.5,  // Confidence range (0.0-1.0)
  minArea: 20               // Minimum building area
}
```

### Map Source

```typescript
mapSourceParams: {
  zoomLevel: 20; // 20+ recommended for precise boundaries
}
```

## Output

Returns GeoJSON with precise building boundary polygons:

```typescript
{
  detections: {
    type: "FeatureCollection",
    features: [
      {
        geometry: { /* precise building polygon */ },
        properties: {}
      }
    ]
  }
}
```
